var fs=require('fs'),restify=require('restify'),path=require('path')

module.exports={
    file:function(req, res, next){
		var filePath=path.join(__dirname,'..','public',(!req.path()||req.path()==='/')?'index.html':req.path())
		fs.stat(filePath,function(err, stats){
			if(err)filePath=path.join(__dirname,'..','public','index.html')
            var stream = fs.createReadStream(filePath)
            stream.on('error', function (err) {
                return next(new restify.NotFoundError())
            })
            stream.on('data', function (d) {
                res.write(d)
            })
            stream.on('end', function () {
                res.end()
                return next()
            })
        })
	}
}
